//
// Created by lfm on 2025/3/3.
//
#include <iostream>
using namespace std;
class MyInt
{
    friend ostream& operator<<(ostream& cout, MyInt myint);
public:
    MyInt()
    {
        m_Num = 0;
    }
    //前置++的重载
    //返回引用的原因是要返回本身才能得到已经++过的值
    MyInt& operator++()
    {
        m_Num++;
        return *this;
    }
    //后置++的重载
    //返回值的原因是，要返回递增之前的值，然后对值进行修改，不返回引用是因为局部变量销毁之后再访问就非法
    MyInt operator++(int)
    {
        MyInt tmp = *this;
        m_Num++;
        return tmp;
    }
private:
    int m_Num;
};
//
ostream& operator<<(ostream & cout, MyInt myint)
{
    cout << myint.m_Num << endl;
}
void test01()
{
    MyInt myint;

    cout << ++(++myint) << endl;
    cout << myint << endl;
}
void test02()
{
    MyInt myInt;

    cout << myInt++ << endl;
    cout << myInt << endl;
}
int main()
{
//    test01();
    test02();
    return 0;
}
#include <iostream>
using namespace std;
class MyInt
{
    friend ostream& operator<<(ostream& cout, MyInt myInt);
public:
    MyInt()
    {
        m_Num = 0;
    }
    MyInt& operator--()
    {
        //先--
        m_Num--;
        //再返回
        return *this;
    }
    MyInt operator--(int)
    {
        MyInt tmp = *this;
        m_Num--;
        return tmp;
    }
private:
    int m_Num;
};
//写后置的时候会报错
ostream& operator<<(ostream& cout, MyInt myInt)//这里的MyInt我用了引用会怎么样？
{
    cout << myInt.m_Num << endl;
}
void test01()
{
    MyInt myint;
    cout << --(--myint) << endl;
}
void test02()
{
    MyInt myint;
    cout << myint-- << endl;
    cout << myint << endl;
}

int main()
{
    test02();
    //test01();
    return 0;
}